package com.fcscs.cservice.gwt.server;

import java.util.Date;
import java.util.List;

import com.fcscs.core.common.SearchResultsContainer;
import com.fcscs.core.gwt.server.FcsRemoteServiceServlet;
import com.fcscs.core.system.ApplicationContextHolder;
import com.fcscs.core.util.CommonUtil;
import com.fcscs.cservice.common.CServiceCommonEnums.BookingStatus;
import com.fcscs.cservice.common.CServiceCommonEnums.BookingViewOrderBy;
import com.fcscs.cservice.common.CServiceCommonEnums.GuestProfileType;
import com.fcscs.cservice.domain.BookingBase;
import com.fcscs.cservice.domain.model.BookingIdAndMessage;
import com.fcscs.cservice.domain.model.BookingIdAndStatus;
import com.fcscs.cservice.domain.model.BookingUpdate;
import com.fcscs.cservice.domain.model.BookingView;
import com.fcscs.cservice.domain.model.NonInHouseGuestProfile;
import com.fcscs.cservice.gwt.client.BookingService;
import com.fcscs.cservice.service.BookingManager;

public class BookingServiceImpl extends FcsRemoteServiceServlet implements BookingService{

	/**
	 * 
	 */
	private static final long serialVersionUID = -9006720430410392759L;
	private BookingManager bkMgr = (BookingManager) ApplicationContextHolder.getBeanFromContext("bookingManager");
	
	
	@SuppressWarnings("unchecked")
	@Override
	public <E extends BookingBase> E get(E cls, long id) {
		return   (E) bkMgr.get(cls.getClass(), id);
	}

	@Override
	public BookingBase get(long id) {
		return bkMgr.get(id);
	}

	@Override
	public Boolean delete(BookingBase loc) {
		return bkMgr.delete(loc);
	}

	@Override
	public void permDelete(BookingBase loc) {
		bkMgr.permDelete(loc);
	}

	@Override
	public <E extends BookingBase> E save(E loc) {
		return  bkMgr.save(loc);
	}

	@Override
	public SearchResultsContainer<BookingView> findBookings(long propId,
			Long restaurantId, String term, String firstName, String lastName,
			String mobileNo, GuestProfileType guestType,Date reservationDate,
			List<BookingStatus> statuses, Date startDate,Date endDate,int start, int resultCnt,
			BookingViewOrderBy orderBy, boolean sortDesc) {
		
		List<BookingView> list =bkMgr.findBookings( propId, restaurantId, term, 
				firstName, lastName, mobileNo,guestType,reservationDate, statuses,startDate,endDate, start, resultCnt, orderBy, sortDesc);
		int cnt = bkMgr.findBookingsCnt( propId, restaurantId, term, 
				firstName, lastName, mobileNo,guestType,reservationDate, statuses,startDate,endDate);
		
		return new SearchResultsContainer<BookingView>(list, cnt);
	}

	@Override
	public SearchResultsContainer<BookingView> simFindBookings(long propId, Long restaurantId, String term, Date reservationDate, int start,int resultCnt) {
		List<BookingView> list= bkMgr.simFindBookings( propId, restaurantId, term, reservationDate, start, resultCnt);
		int cnt = bkMgr.simFindBookingsCnt( propId, restaurantId, term, reservationDate);
		
		return new SearchResultsContainer<BookingView>(list, cnt);
	}
	
	@Override
	public List<BookingIdAndMessage> updateBookingStatus(long propId,List<BookingIdAndStatus> idstatus) {
		List<BookingIdAndMessage> list = bkMgr.updateBookingStatus( propId, idstatus);
		return list;
	}

	@Override
	public SearchResultsContainer<BookingView> getBookingHistory(long propId,long guestId,int start, int resultCnt) {
		List<BookingView> list = bkMgr.getBookingHistory(propId, guestId, start, resultCnt);
		int cnt = bkMgr.getBookingHistoryCnt( propId, guestId);
		return new SearchResultsContainer<BookingView>(list, cnt);
	}

	@Override
	public BookingView createBooking(BookingBase bkBase,NonInHouseGuestProfile nonInGuest) {
		bkBase.setOrgId(CommonUtil.getUserContext().getOrgId());
		bkBase.setPropertyId(CommonUtil.getUserContext().getPropertyId());
		BookingView model= bkMgr.createBooking(bkBase, nonInGuest);
		return model;
	}

	@Override
	public BookingView updateBooking(BookingUpdate bookingUpdate) {
		bookingUpdate.setOrgId(CommonUtil.getUserContext().getOrgId());
		bookingUpdate.setPropertyId(CommonUtil.getUserContext().getPropertyId());
		BookingView model = bkMgr.updateBooking(bookingUpdate);
		return model;
	}
	
}
